/**
 * 
 */
package com.zhiteng.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhiteng.entity.SysDict;
import com.zhiteng.service.CourseTableService;
import com.zhiteng.service.SysDictService;
import com.zhiteng.utils.common.ZTResult;

/**  
* <p>Title: SelectController.java</p>  
* <p>Description: 页面中下拉框获取数据的Controller</p>  
* @author dragon  
* @date 2018年11月15日  
* @version 1.0  
*/
@Controller
@RequestMapping("/select")
public class SelectController {
	
	@Autowired
	private CourseTableService courseTableService;
	@Autowired
	private SysDictService sysDictService;
	
	/**
	 * 
	* @Title: queryCourseNameBySchool  
	* @Description: 根据学校名称查找所有学科名称
	* @param schoolName	学校名称
	* @return ZTResult<List<String>>   
	* @throws
	 */
	@RequestMapping("/queryCourseNameBySchool")
	@ResponseBody
	public ZTResult<List<String>> queryCourseNameBySchool(
			@RequestParam(name="schoolName")String schoolName){
		if(StringUtils.isBlank(schoolName)) {
			return ZTResult.result(1,"查询失败，请检查参数");
		}
		List<String> courseNameList =  courseTableService.queryCourseNameBySchool(schoolName);
		
		return ZTResult.result(0, "查询成功", courseNameList);
	}
	
	/**
	 * 
	* @Title: queryTeacherNameBySchoolAndCourse  
	* @Description: 根据学校名称和课程名称查找所有老师姓名 
	* @param schoolName	学校名称
	* @param courseName 课程名称
	* @return ZTResult<List<String>>   
	* @throws
	 */
	@RequestMapping("/queryTeacherNameBySchoolAndCourse")
	@ResponseBody
	public ZTResult<List<String>> queryTeacherNameBySchoolAndCourse(
			@RequestParam(name="schoolName")String schoolName,
			@RequestParam(name="courseName")String courseName){
		if(StringUtils.isAnyBlank(schoolName,courseName)) {
			return ZTResult.result(1,"查询失败，请检查参数");
		}
		
		List<String> TeacherNameList =  courseTableService.queryTeacherNameBySchoolAndCourse(schoolName,courseName);
		
		return ZTResult.result(0, "查询成功", TeacherNameList);
	}
	
	/**
	 * 
	* @Title: queryGradeBySchool  
	* @Description: 根据学校名称查找对应的所有年级
	* @param schoolName	学校名称
	* @return ZTResult<List<String>>   
	* @throws
	 */
	@RequestMapping("/queryGradeBySchool")
	@ResponseBody
	public ZTResult<List<String>> queryGradeBySchool(
			@RequestParam(name="schoolId")String schoolId){
		if(StringUtils.isBlank(schoolId)) {
			return ZTResult.result(1,"查询失败，请检查参数");
		}
		List<String> gradeList = courseTableService.queryGradeBySchool(schoolId);
		
		return ZTResult.result(0, "查询成功", gradeList);
	}
	
	
	/**
	 * 
	* @Title: queryClassBySchoolAndGrade  
	* @Description: 根据学校名称和年级查找对应的所有班级
	* @param schoolName 学校名称
	* @param gradeName	年级名称
	* @return ZTResult<List<String>>   
	* @throws
	 */
	@RequestMapping("/queryClassBySchoolAndGrade")
	@ResponseBody
	public ZTResult<List<String>> queryClassBySchoolAndGrade(
			@RequestParam(name="schoolId")String schoolId,
			@RequestParam(name="gradeName")String gradeName){
		if(StringUtils.isAnyBlank(schoolId,gradeName)) {
			return ZTResult.result(1,"查询失败，请检查参数");
		}
		List<String> classList = courseTableService.queryClassBySchoolAndGrade(schoolId,gradeName);
		return ZTResult.result(0, "查询成功", classList);
	}
	
	/**
	 * 
	* @Title: queryLeaveType  
	* @Description: 查询数据字典（如加载请假类型）
	* @param schoolId	学校id
	* @param type(请假的type=leave)	数据字典类型
	* @return ZTResult<List<String>>   
	* @throws
	 */
	@RequestMapping("/queryDictList")
	@ResponseBody
	public ZTResult<List<SysDict>> queryDictList(
			@RequestParam(name="schoolId")String schoolId,String type){
		if(StringUtils.isAnyBlank(schoolId,type)) {
			return ZTResult.result(1,"查询失败，请检查参数");
		}
		List<SysDict> dictList = sysDictService.queryDictBySchoolIdAndType(schoolId,type);
		return ZTResult.result(0, "查询成功",dictList);
	}
	
}
